﻿using System;
using System.Collections.Generic;
using System.Text;
using ITAP.ShprossesBuilder.Modelling;
using System.Drawing;
using ITAP.ShprossesBuilder.Modelling.Components;
using ITAP.Core.Modelling;

namespace ITAP.ShprossesBuilder.Calculations.CoordinateTransformations
{
    public class GlobalToInnerSpacerCoordinateTransformer : ICoordinateTransformer
    {

        private bool enabled = true;

        public bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }

        #region ICoordinateTransformer Members

        public ModelPoint TransformTo(ITAP.ShprossesBuilder.Modelling.Components.ModelContainer container, ModelPoint point)
        {
            if (container.ActiveCell == null || !enabled)
                return (ModelPoint)point.Clone();
            ModelCell cell = container.ActiveCell as ModelCell;
            RectangleF modelBBox = cell.Model.BoundingBox;
            return new ModelPoint(point.X - modelBBox.X - cell.Model.SpacerWidth, point.Y - modelBBox.Y - cell.Model.SpacerWidth);
            
        }

        public ModelPoint TransformFrom(ITAP.ShprossesBuilder.Modelling.Components.ModelContainer container, ModelPoint point)
        {
            if (container.ActiveCell == null || !enabled)
                return (ModelPoint)point.Clone();
            ModelCell cell = container.ActiveCell as ModelCell;
            RectangleF modelBBox = cell.Model.BoundingBox;
            return new ModelPoint(point.X + modelBBox.X + cell.Model.SpacerWidth, point.Y + modelBBox.Y + cell.Model.SpacerWidth);
        }

        #endregion
    }
}
